<script type="text/javascript">
    function onChangeMediaType(s){
        if(jQuery(s).val() == "none"){
            jQuery("#media-image").fadeOut();
            jQuery("#media-youtube").fadeOut();
        } else if(jQuery(s).val() == "image"){
            jQuery("#media-image").fadeIn();
            jQuery("#media-youtube").fadeOut();
        } else if(jQuery(s).val() == "youtube") {
            jQuery("#media-image").fadeOut();
            jQuery("#media-youtube").fadeIn();
        }
    }
</script>

<div class="row-fluid">
    <div class="span12">
        <ul class="quicktasks">		
                <li>
                        <a href="?action=editcalendar"> <img
                                        src="<?php echo $view->layoutUrl;?>/assets/img/icons/essen/32/back.png"
                                        alt=""> <span>Back</span>
                        </a>
                </li>
        </ul>
        <div class="box">
            <div class="box-head">
                <h3>Edit media for <?php echo $view->question['day_num'];?>.March</h3>
            </div>
            <div class="box-content">
                <div style="color:red;">
                    <?php echo $view->error;?>
                </div>
                <form method="post" enctype="multipart/form-data" class="form-horizontal">
                    <fieldset>                        
                        <input type="hidden" name="question_day_id" value="<?php echo $_GET['question_day_id']; ?>" />
                        
                        <div class="control-group">
                            <label for="select" class="control-label">Select media type</label>
                            <div class="controls">
                                <select name="media_type" id="select" onchange="onChangeMediaType(this);">
                                     <option <?php if($view->question['media_type'] == "none"){ ?>selected="selected"<?php } ?> value="none">None</option>
                                    <option <?php if($view->question['media_type'] == "image"){ ?>selected="selected"<?php } ?> value="image">Image</option>
                                    <option <?php if($view->question['media_type'] == "youtube"){ ?>selected="selected"<?php } ?> value="youtube">YouTube video</option>
                                </select>                                                    
                            </div>
                        </div>
                        <div id="media-image" <?php if($view->question['media_type'] != "image"){ ?> style="display:none;"<?php } ?>>
                            <div class="control-group">
                                <label for="image_link" class="control-label">Image link</label>
                                <div class="controls">
                                    <input value="<?php echo $view->question['image_link'];?>" type="text" name="image_link" id="image_link" class='input-square'>
                                </div>
                            </div>

                            <div class="control-group">
                                <label for="file" class="control-label">Choose picture</label>
                                <div class="controls">
                                    <input type="file" name="picturefile" id="file">                                                                    
                                    <br/>
                                    <strong>Max image size possible to upload is 2MB</strong>
                                </div>
                            </div>
                            
                            <?php if($view->question['picture_url'] != "") {?>
                            <div class="control-group">
                                <label for="" class="control-label"></label>
                                <div class="controls">
                                    <?php
                                    $imgurl = $view->question['picture_url'];
                                    if($imgurl){
                                        if(substr($imgurl, 0, 4) != "http"){
                                            $imgurl = "../" . $imgurl;
                                        }
                                    }
                                    ?>
                                    <img src="<?php echo $imgurl;?>" width="300" />
                                </div>
                            </div>                            
                            <?php } ?>                            
                            
                        </div>
                        
                        <div id="media-youtube" <?php if($view->question['media_type'] != "youtube"){ ?> style="display:none;"<?php } ?>>                     
                            <div class="control-group">
                                <label for="video_url" class="control-label">Choose Youtube URL</label>
                                <div class="controls">
                                    <input value="<?php echo $view->question['video_url'];?>" type="text" name="video_url" id="video_url" class='input-square'>
                                </div>
                            </div>
                            
                            <br/>
                            <?php if($view->question['video_url'] != "") {?>
                            
                                <div class="control-group">
                                    <label for="video_url" class="control-label"></label>
                                    <div class="controls">
                                        <object width="360" height="202"><param name="movie" value="<?php echo $view->question['video_url'];?>"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="<?php echo $view->question['video_url'];?>" type="application/x-shockwave-flash" width="360" height="202" allowscriptaccess="always" allowfullscreen="true"></embed></object>
                                    </div>
                                </div>
                            
                            <?php } ?>                     
                        </div>
                        
                        <div class="form-actions">
                            <button class="btn btn-primary" type="submit">Send</button>
                            <input type="reset" class='btn btn-danger' value="reset">
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>
    </div>
</div>